<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@page import="java.io.Console"%>
<%@page import="java.sql.*" %>
<%@page import="java.util.logging.ConsoleHandler"%>
<%@page import="utility.connections"%>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<%! String user,type,matr,cogn,pwd,nome,cognome,email,matricola,tipologia,codicefiscale; %>
<%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			user = session.getAttribute("user").toString().toLowerCase();
			type = session.getAttribute("type").toString();
			matr = session.getAttribute("matricola").toString();
			nome = session.getAttribute("nome").toString();
			cogn = session.getAttribute("cognome").toString();
			}
%>
<script type="text/javascript">
function prepareQry(formName)
{
	var qry="";
	var dummy;
	
	dummy=document.forms[formName].elements['txtMatr'].value.toUpperCase();
	if (dummy.trim()!="") qry = qry + " matricola = "        + dummy + "   AND ";
	
	dummy=document.forms[formName].elements['txtCF'].value.toUpperCase();
	if (dummy.trim()!="") qry = qry + " codicefiscale like '" + dummy + "%' AND ";
	
	dummy=document.forms[formName].elements['txtCogn'].value.toUpperCase();;
	if (dummy.trim()!="") qry = qry + " cognome like '"      + dummy + "%' AND ";
	
	dummy=document.forms[formName].elements['txtNome'].value.toUpperCase();;
	if (dummy.trim()!="") qry = qry + " nome like '"         + dummy + "%' AND ";
	
	document.frmQry.txtQry.value=qry;
}

function back()
{
	document.frmQry.action="../hamm.jsp";
	document.frmQry.submit;
	
}

function find()
{
	document.frmQry.action="elenco_dip.jsp";
	prepareQry('frmQry');
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ELENCO DIPENDENTI </title>
</head>
<body>

<div align="center">
  <h1>ELENCO DIPENDENTI </h1>
  <p>&nbsp;</p>
</div>
<form action="" method="post" name="frmQry">
	<input type="text" name="txtQry" style="visibility:hidden" />
	<table height="30" width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
	    <td colspan="3" rowspan="5">&nbsp;</td>
	    <td width="17%">MATRICOLA</td>
	    <td width="40%"><input type="text" name="txtMatr" value="" /></td>
	    <td colspan="3" rowspan="5">&nbsp;</td>
      </tr>
	  <tr>
	    <td>CODICE FISCALE </td>
	    <td><input type="text" name="txtCF" value="" /></td>
      </tr>
	  <tr>
	    <td>COGNOME</td>
	    <td><input type="text" name="txtCogn" value="" /></td>
      </tr>
	  <tr>
	    <td>NOME</td>
	    <td><input type="text" name="txtNome" value="" /></td>
      </tr>
	  <tr>
	    <td colspan="7"><div align="center">
	      <input type="submit" name="cmdBack" value="INDIETRO" onClick="javascript:back();">
          <input type="submit" name="cmdFind" value="CERCA"    onclick="javascript:find();">
	    </div></td>
      </tr>
	</table>
</form>
<h2 align="center">&nbsp;</h2>
<h2 align="center">SELEZIONARE DIPENDENTI A CUI EFFETTUARE L'ALLOCAZIONE</h2>
<form name="queryDel" action="" method="post">
	<input type="text" size="40%" name="iddel" value="" style="visibility:hidden;" />
	<table width="100%" border="1" cellspacing="0" cellpadding="2">
	  <tr>
	    <td bgcolor="#FFFF99" class="style1" style="border:1px solid;"><div align="center"><strong>PROG.</strong></div></td>
	    <td bgcolor="#FFFF99" class="style1" style="border:1px solid;"><div align="center"><strong>MATRICOLA</strong></div></td>
	    <td bgcolor="#FFFF99" class="style1" style="border:1px solid;"><div align="center"><strong>CODICE FISCALE </strong></div></td>
	    <td bgcolor="#FFFF99" class="style1" style="border:1px solid;"><div align="center"><strong>NOME</strong></div></td>
	    <td bgcolor="#FFFF99" class="style1" style="border:1px solid;"><div align="center"><strong>COGNOME</strong></div></td>
	    <td bgcolor="#FFFF99" class="style1" style="border:1px solid;"><div align="center"><strong>ELIMINA</strong></div></td>
	  </tr>
	  
	  <% 
	String qry=request.getParameter("txtQry");
    if (qry!=null && qry.endsWith("AND "))
    	qry=" and " + qry.subSequence(1,qry.length()-4);
    else
    	qry = "";
	
    qry = "select * from personale where matricola in(select matricola from account where tipologia='3') " + qry + " order by cognome,nome";
 	System.out.println(qry);
	ResultSet rs;
	rs = connections.getStatement().executeQuery(qry);
	int i=0;
	
	if(rs.isBeforeFirst()&&rs.isAfterLast())
	{
		out.println("<script language = \"text/vbscript\"> alert(\"Non ci sono record!!!\"); </script>");
	}
	else
	{
		
		while (rs.next())
		{
			matricola = 	rs.getString("matricola");
			codicefiscale = rs.getString("codicefiscale");
			nome = 			rs.getString("nome");
			cognome =		rs.getString("cognome");
			
			String color;
            		String bordercell;
            		
            		i++;
            		
            		if (i%2==0)
            		{
            			color ="\"#E0E0E0\"";
            			bordercell="style=\"border:1px solid;\";";
            		}
            		else
            		{
            			color = "\"#EFFFEF\"";
            			bordercell="style=\"border:1px solid;\";";
            		}
            		out.println("<tr>");
            		out.println("<td align=\"right\""+bordercell+" class=\"style1\" bordercolor=\"#555555\" bgcolor = "+color+ ">" + i + "</td>"); //prog.
            		out.println("<td "+bordercell+" class=\"style1\" bordercolor=\"#555555\" bgcolor = "+color+ ">"+ matricola+"</td>");
            		out.println("<td "+bordercell+" class=\"style1\" bordercolor=\"#555555\" bgcolor = "+color+ ">" + codicefiscale + "</td>");
            		out.println("<td "+bordercell+" class=\"style1\" bordercolor=\"#555555\" bgcolor = "+color+ ">" + nome + "</td>");
            		out.println("<td "+bordercell+" class=\"style1\" bordercolor=\"#555555\" bgcolor = "+color+ ">" + cognome + "</td>");
            		out.println("<td "+bordercell+" class=\"style1\" bordercolor=\"#555555\" bgcolor = "+color+ "><a href=\"select_bene.jsp?matricola="+matricola+"&gdl=0\">" + "assegna" + "</a></td>");
            		
	}
	}
	 %>
	</table>
</form>
<p>&nbsp;</p>

</body>
</html>